var Sound = Class.create();
Sound.prototype = {
	SE_FILE_NAMES : [
		"se01",
		"se02"
	],
	BGM_FILE_NAMES : [
		"bgm01"
	],
	seArray : null,
	bgm : null,
	isLoop : false,
	
	initialize : function() {
		var myAudio;
		try {
			myAudio = new Audio("");
			this.audioObjSupport = true;
		} catch(e) {
			this.audioObjSupport = false;
			return;
		}
		
		if (myAudio.canPlayType) {
			// 今のところ、canPlayType(type) は次のいずれかを返す： "", "maybe", "probably"
			this.canPlayOgg = ("no" != myAudio.canPlayType("audio/ogg")) && ("" != myAudio.canPlayType("audio/ogg"));
			this.canPlayMp3 = ("no" != myAudio.canPlayType("audio/mpeg")) && ("" != myAudio.canPlayType("audio/mpeg"));
		}
		
		if (this.canPlayOgg) {
			this.ext = ".ogg";
		} else if (this.canPlayMp3) {
			this.ext = ".mp3";
		} else {
			return;
		}
		
		this.seArray = new Array(this.SE_FILE_NAMES.length);
		for (var i = 0; i < this.SE_FILE_NAMES.length; i++) {
			this.seArray[i] = new Audio(RES_URL + this.SE_FILE_NAMES[i] + this.ext);
		}
	},
	
	playSE : function(num) {
		if (!this.audioObjSupport) {
			return;
		}
		this.seArray[num].pause();
		this.seArray[num].play();
	},
	
	stopSE : function(num) {
		if (!this.audioObjSupport) {
			return;
		}
		this.seArray[num].pause();
	},
	
	playBGM : function(num, isLoop) {
		if (!this.audioObjSupport) {
			return;
		}
		if (this.bgm != null) {
			this.bgm.pause();
		}
		this.bgm = new Audio(RES_URL + this.BGM_FILE_NAMES[num] + this.ext);
		if (isLoop) {
			var localBgm = this.bgm;
			Event.observe(this.bgm, 'ended', function() { localBgm.play(); }, false);
		}
		this.bgm.play();
		this.isLoop = isLoop;
	},
	
	pauseBGM : function() {
		if (!this.audioObjSupport) {
			return;
		}
		this.bgm.pause();
		this.bgm = null;
	}
}